package org.rsbot.script.randoms;

import org.rsbot.script.Random;
import org.rsbot.script.ScriptManifest;
import org.rsbot.script.methods.Calculations;
import org.rsbot.script.methods.Camera;
import org.rsbot.script.methods.Interfaces;
import org.rsbot.script.methods.NPCs;
import org.rsbot.script.methods.Objects;
import org.rsbot.script.methods.Walking;
import org.rsbot.script.wrappers.RSComponent;
import org.rsbot.script.wrappers.RSNPC;
import org.rsbot.script.wrappers.RSObject;
import org.rsbot.script.wrappers.RSPlayer;
import org.rsbot.script.wrappers.RSTile;

@ScriptManifest(authors={"Taha"}, name="FirstTimeDeath", version=1.1D)
public class FirstTimeDeath extends Random
{
  private int step;
  private boolean exit;
  private RSNPC reaper;

  public boolean activateCondition()
  {
    if ((this.reaper = this.npcs.getNearest(new int[] { 8869 })) == null);
    return (this.reaper = this.npcs.getNearest(new int[] { 8870 })) != null;
  }

  public int loop()
  {
    if (!activateCondition())
      return -1;
    this.camera.setPitch(true);
    if ((this.interfaces.canContinue()) && (!this.exit)) {
      if (this.interfaces.getComponent(241, 4).getText().contains("Yes?")) {
        this.step += 1;
        this.exit = true;
        return random(200, 400);
      }if (this.interfaces.getComponent(242, 5).getText().contains("Enjoy!")) {
        this.step += 1;
        this.exit = true;
      }
      this.interfaces.clickContinue();
      return random(200, 400);
    }
    switch (this.step) {
    case 0:
      RSObject localRSObject1 = this.objects.getNearest(new int[] { 45802 });
      localRSObject1.doAction("Talk-to");
      sleep(random(1000, 1200));
      if (this.interfaces.canContinue()) break;
      this.walking.walkTileOnScreen(new RSTile(this.reaper.getLocation().getX() + 2, this.reaper.getLocation().getY() + 1));
      this.camera.turnToObject(localRSObject1); break;
    case 1:
      int i = 45803;
      RSObject localRSObject2 = this.objects.getNearest(new int[] { i });
      RSTile localRSTile = getMyPlayer().getLocation();
      localRSObject2.doAction("Enter");
      sleep(random(1000, 1200));
      if (this.calc.distanceTo(localRSTile) >= 10) break;
      this.camera.turnToObject(localRSObject2);
      if (this.calc.tileOnScreen(localRSObject2.getLocation())) break;
      this.walking.walkTileOnScreen(localRSObject2.getLocation());
    }

    return random(200, 400);
  }

  public void onFinish()
  {
  }
}